Added gtk_extended_layout_is_height_for_width()
authorTristan Van Berkom <tristan.van.berkom@gmail.com>
Sun, 11 Apr 2010 02:32:55 +0000 (22:32 -0400)
committerTristan Van Berkom <tristan.van.berkom@gmail.com>
Sun, 11 Apr 2010 02:32:55 +0000 (22:32 -0400)
Added an indicator telling whether a widget prefers to be allocated
as height-for-width or width-for-height. Usually this depends on the
orientation of a container or the nature of a content widget like GtkLabel.

This indicator is only used in the seldom case where a parent is allocating
free space to the child and the child can flow in either direction, GtkWindow
and GtkScrolledWindow are users of this api.

gtk/gtk.symbols
gtk/gtkextendedlayout.c
gtk/gtkextendedlayout.h

index dbbfa39f4c2d68c8b3a3ee2e95ad4e5ef0f0847f..97838cd003f0ca53a7cdaa35e14c7847d48bb033 100644 (file)
@@ -1517,6 +1517,7 @@ gtk_extended_layout_get_type G_GNUC_CONST
 gtk_extended_layout_get_desired_size
 gtk_extended_layout_get_height_for_width
 gtk_extended_layout_get_width_for_height
+gtk_extended_layout_is_height_for_width
 #endif
 #endif
 
index 9b9c9cef04af4e3263055a09f4156e05a624ec11..a8293e32de7153ad7252aa1627eb763ca15a4bb1 100644 (file)
@@ -70,6 +70,37 @@ gtk_extended_layout_get_desired_size (GtkExtendedLayout *layout,
   _gtk_size_group_compute_desired_size (GTK_WIDGET (layout), minimum_size, natural_size);
 }
 
+
+
+/**
+ * gtk_extended_layout_is_height_for_width:
+ * @layout: a #GtkExtendedLayout instance
+ *
+ * Gets whether the widget prefers a height-for-width layout
+ * or a width-for-height layout
+ *
+ * Returns: %TRUE if the widget prefers height-for-width, %FALSE if
+ * the widget should be treated with a width-for-height preference.
+ *
+ * Since: 3.0
+ */
+gboolean
+gtk_extended_layout_is_height_for_width (GtkExtendedLayout *layout)
+{
+  GtkExtendedLayoutIface *iface;
+
+  g_return_val_if_fail (GTK_IS_EXTENDED_LAYOUT (layout), FALSE);
+
+  iface = GTK_EXTENDED_LAYOUT_GET_IFACE (layout);
+  if (iface->is_height_for_width)
+    return iface->is_height_for_width (layout);
+
+  /* By default widgets are height-for-width. */
+  return TRUE;
+}
+
+
+
 /**
  * gtk_extended_layout_get_width_for_height:
  * @layout: a #GtkExtendedLayout instance
@@ -92,6 +123,12 @@ gtk_extended_layout_get_width_for_height (GtkExtendedLayout *layout,
 
   g_return_if_fail (GTK_IS_EXTENDED_LAYOUT (layout));
 
+  /* XXX Maybe here we do _gtk_size_group_compute_width_for_height()
+   * and return hard coded minimum widths/heights for for widgets with
+   * explicit size requests as well as fetch the common minimum/natural
+   * widths/heights for size grouped widgets.
+   */
+
   iface = GTK_EXTENDED_LAYOUT_GET_IFACE (layout);
   iface->get_width_for_height (layout, height, minimum_width, natural_width);
 
index 9944fedad8ad8ef9aa8c1975eb3b1890cc36afe4..1d0d531d425de60a56df27f90c3da2dc3f617728 100644 (file)
@@ -42,32 +42,41 @@ struct _GtkExtendedLayoutIface
 
   /* virtual table */
 
-  void (*get_desired_size)     (GtkExtendedLayout  *layout,
-                                GtkRequisition     *minimum_size,
-                                GtkRequisition     *natural_size);
-  void (*get_width_for_height) (GtkExtendedLayout  *layout,
-                                gint                height,
-                                gint               *minimum_width,
-                                gint               *natural_width);
-  void (*get_height_for_width) (GtkExtendedLayout  *layout,
-                                gint                width,
-                                gint               *minimum_height,
-                                gint               *natural_height);
+
+  /* TODO: Change for get_desired_width()/get_desired_height() for clarity sake */
+  void      (* get_desired_size)     (GtkExtendedLayout  *layout,
+                                     GtkRequisition     *minimum_size,
+                                     GtkRequisition     *natural_size);
+  
+  gboolean  (* is_height_for_width)  (GtkExtendedLayout  *layout);
+  
+  void      (* get_width_for_height) (GtkExtendedLayout  *layout,
+                                     gint                height,
+                                     gint               *minimum_width,
+                                     gint               *natural_width);
+  void      (* get_height_for_width) (GtkExtendedLayout  *layout,
+                                     gint                width,
+                                     gint               *minimum_height,
+                                     gint               *natural_height);
 };
 
-GType gtk_extended_layout_get_type             (void) G_GNUC_CONST;
-
-void  gtk_extended_layout_get_desired_size     (GtkExtendedLayout *layout,
-                                                GtkRequisition    *minimum_size,
-                                                GtkRequisition    *natural_size);
-void  gtk_extended_layout_get_width_for_height (GtkExtendedLayout *layout,
-                                                gint               height,
-                                                gint              *minimum_width,
-                                                gint              *natural_width);
-void  gtk_extended_layout_get_height_for_width (GtkExtendedLayout *layout,
-                                                gint               width,
-                                                gint              *minimum_height,
-                                                gint              *natural_height);
+GType     gtk_extended_layout_get_type             (void) G_GNUC_CONST;
+
+void      gtk_extended_layout_get_desired_size     (GtkExtendedLayout *layout,
+                                                   GtkRequisition    *minimum_size,
+                                                   GtkRequisition    *natural_size);
+
+
+gboolean  gtk_extended_layout_is_height_for_width  (GtkExtendedLayout *layout);
+void      gtk_extended_layout_get_width_for_height (GtkExtendedLayout *layout,
+                                                   gint               height,
+                                                   gint              *minimum_width,
+                                                   gint              *natural_width);
+void      gtk_extended_layout_get_height_for_width (GtkExtendedLayout *layout,
+                                                   gint               width,
+                                                   gint              *minimum_height,
+                                                   gint              *natural_height);
+
 
 G_END_DECLS